home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / tools / fixtai.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-02  |  10.6 KB  |  291 lines

  1. /*****************************************************************************
  2. * Program to suck up the 'mchan' lines from the tailoring file and produce   *
  3. * a suitable block of structure initializers for inclusion in conf_chan.c    *
  4. *                                                                            *
  5. * This program relies on having an existing installation with all channels   *
  6. * defined in a tailoring file (whose name is supplied as the first argument).*
  7. * Pre-compiled channels and tables are ignored.                              *
  8. *                                                                            *
  9. * This program uses mmdf_init to read in the (alternate) tailor file and     *
  10. * then passes the channel and table structure arrays to an internal          *
  11. * structure-initializer-printer.  This output is then #included into         *
  12. * conf_chan.c and forms the basis for the next installation of MMDF.         *
  13. *                                                                            *
  14. * Fri Apr 13 13:07:49 EST 1984, bpc (BBN)                                    *
  15. * Tue Nov 27 11:45:21 EST 1984, dbl (BBN)                                    *
  16. /*****************************************************************************
  17. * Added processing of 'mtbl' lines, also.                                    *
  18. * Mon Apr 23 09:59:59 EST 1984, bpc                                          *
  19. /*****************************************************************************
  20. * Added processing of 'alias' lines, also.                                   *
  21. * Mon Dec  8 09:59:59 EST 1986, dbl                                          *
  22. *****************************************************************************/
  23.  
  24. #include "util.h"
  25. #include "cmd.h"
  26. #include "ch.h"
  27. #include <sys/stat.h>
  28. #include "ap.h"
  29. #include "conf.h"
  30.  
  31. #define MAXARG 50
  32.  
  33. extern int errno;
  34. extern char * malloc();
  35. extern int tb_numtables;
  36. extern int ch_numchans;
  37. extern Table **tb_list;
  38. extern Chan **ch_tbsrch;
  39. extern char *mmtailor;
  40. extern Alias *al_list;
  41.  
  42. /* */
  43. main (argc, argv)
  44.     char * argv[];
  45. {
  46.     if (argc != 2)
  47.     {
  48.     fprintf (stderr, "usage: %s tailoringfile_name\n", argv[0]);
  49.     exit (1);
  50.     }
  51.  
  52.     mmtailor = argv[1];        /* use alternate tailor file */
  53.  
  54.     al_list = (Alias *) 0;      /* zero the pre-compiled alias linked-list */
  55.     tb_numtables = 0;           /* zero the pre-compiled table array */
  56.     tb_list[0] = (Table *) 0;
  57.     ch_numchans = 0;            /* zero the pre-compiled channel array */
  58.     ch_tbsrch[0] = (Chan *) 0;
  59.  
  60.     mmdf_init(argv[0]);
  61.     dump_it();
  62.     exit (0);
  63. }
  64.  
  65. /*****************************************************************************
  66. *                            | d u m p _ i t |                               *
  67. *                             ***************                                *
  68. * this routine is the real point of all this: it is the routine to           *
  69. * pass over the channels and tables we've defined and appropriately          *
  70. * initialize them                                                            *
  71. *****************************************************************************/
  72. dump_it ()
  73. {
  74.     dump_tables();
  75.     printf ("/*\f*/\n");
  76.     dump_channels();
  77.     dump_aliases();
  78. }
  79.  
  80. /*****************************************************************************
  81. *                         | d u m p _ t a b l e s |                          *
  82. *                          ***********************                           *
  83. * Print out all of the pre-initialized tables.                               *
  84. *****************************************************************************/
  85. dump_tables()
  86. {
  87.     register i;
  88.  
  89.     printf ("LOCVAR Table _tblist[]");
  90.     printf ("\t/* Data blocks for the pre-initialized tables */\n");
  91.     printf ("\t=\n");
  92.     printf ("{\n");
  93.     for (i = 0; i < tb_numtables; i++)
  94.       set_tb (tb_list[i]);
  95.     printf ("};\n");
  96.     printf ("LOCVAR Table * tblist[NUMTABLES+1]\t/* all known tables */\n");
  97.     printf ("\t=\n");
  98.     printf ("{\n");
  99.     for (i = 0; i < tb_numtables; i++)
  100.       printf ("    &_tblist[%d],\n", i);
  101.     printf ("    (Table *) 0\n};\n");
  102.     printf ("int\ttb_numtables = %d;\t/* Number of preinitialized tables */\n",
  103.         tb_numtables);
  104. }
  105.  
  106. /*****************************************************************************
  107. *                       | d u m p _ c h a n n e l s |                        *
  108. *                        ***************************                         *
  109. * Now print out all the channel definitions.  The 'table' pointer for        *
  110. * each channel will simply be the same pointer to the _tblist array          *
  111. * that tblist uses                                                           *
  112. *****************************************************************************/
  113. dump_channels()
  114. {
  115.     register i;
  116.  
  117.     printf ("LOCVAR Chan _chsrch[]");
  118.     printf ("\t/* Data blocks for the pre-initialized channels */\n");
  119.     printf ("\t=\n");
  120.     printf ("{\n");
  121.     for (i = 0; i < ch_numchans; i += 1)
  122.       set_ch (ch_tbsrch[i]);
  123.     printf ("};\n");
  124.     printf ("LOCVAR Chan * chsrch[NUMCHANS+1]\t/* order chan tables searched */\n");
  125.     printf ("\t=\n");
  126.     printf ("{\n");
  127.     for (i = 0; i < ch_numchans; i += 1)
  128.       printf ("    &_chsrch[%d],\n", i);
  129.     printf ("    (Chan *) 0\n};\n");
  130.     printf ("int\tch_numchans = %d;\t/* Number of preinitialized channels */\n",
  131.         ch_numchans);
  132. }
  133. /*****************************************************************************
  134. *                         | d u m p _ a l i a s e s |                        *
  135. *                          *************************                         *
  136. * Print out all of the pre-initialized aliases.                              *
  137. *****************************************************************************/
  138. dump_aliases()
  139. {
  140.     register int i;
  141.     register Alias *alptr;
  142.  
  143.     if (al_list == (Alias *) 0) {
  144.     printf ("Alias * al_list = (Alias *) 0;\n");
  145.         return;
  146.     }
  147.  
  148.     printf ("LOCVAR Alias _allist[]");
  149.     printf ("\t/* Data blocks for the pre-initialized aliases */\n");
  150.     printf ("\t=\n");
  151.     printf ("{\n");
  152.     for (i = 0, alptr = al_list; 
  153.      alptr != (Alias *) 0; 
  154.      alptr = alptr->al_next, i++)
  155.       set_al (alptr,i);
  156.     printf ("\n};\n");
  157.     printf ("Alias * al_list = &_allist[0];\t/* List of aliases */\n");
  158. }
  159. /* */
  160. /*****************************************************************************
  161. *                              | s e t _ t b |                               *
  162. *                               *************                                *
  163. * Set the initialization for one entry of a table                            *
  164. *****************************************************************************/
  165. set_tb (tptr)
  166.     register Table * tptr;
  167. {
  168.     printf ("    { ");
  169.     str_print (tptr->tb_name);
  170.     printf (", ");
  171.     str_print (tptr->tb_show);
  172.     printf (", ");
  173.     str_print (tptr->tb_file);
  174.     printf (", (FILE *)0, 0L, 0%o },\n", (int)tptr->tb_flags);
  175. }
  176. /*****************************************************************************
  177. *                              | s e t _ a l |                               *
  178. *                               *************                                *
  179. * Set the initialization for one entry of a table                            *
  180. *****************************************************************************/
  181. set_al (aptr,ind)
  182.     register Alias * aptr;
  183.     register int ind;
  184. {
  185.     printf ("    { ");
  186.     printf ("0%o, ", (int)aptr->al_flags);
  187.     table_print(aptr->al_table);
  188.     if (aptr->al_next == (Alias *) 0)
  189.     printf(", (Alias *) 0 }\n");
  190.     else
  191.     printf (", &_allist[%d] },\n",ind+1);
  192. }
  193. /*****************************************************************************
  194. *                         | t a b l e _ p r i n t |                          *
  195. *                          ***********************                           *
  196. * Given a table pointer, print it out as an pointer into the array of table  *
  197. * structures.                                                                *
  198. *****************************************************************************/
  199. table_print (tptr)
  200.     Table * tptr;
  201. {
  202.     register i;
  203.  
  204.     if (tptr == (Table *) 0)
  205.     printf ("(Table *)0");
  206.     else
  207.     {
  208.         for (i = 0; i < tb_numtables; i += 1)
  209.         if (tb_list[i] == tptr)
  210.         {
  211.         printf ("&_tblist[%d]", i);
  212.             return;
  213.         }
  214.         fprintf (stderr, "Can't locate table %o\n", tptr);
  215.     (void) fflush (stdout);
  216.         abort ();
  217.     }
  218. }
  219. /*****************************************************************************
  220. *                           | s t r _ p r i n t |                            *
  221. *                            *******************                             *
  222. * Print out a string if non-null, 0 otherwise                                *
  223. *****************************************************************************/
  224. str_print (ptr)
  225.     char * ptr;
  226. {
  227.     if (ptr == (char *)0)
  228.     printf ("(char *)0");
  229.     else
  230.     printf ("\"%s\"", ptr);
  231. }
  232. /* */
  233. /*****************************************************************************
  234. *                              | s e t _ c h |                               *
  235. *                               *************                                *
  236. * Initialize one channel                                                     *
  237. *****************************************************************************/
  238. set_ch (cptr)
  239.     register Chan * cptr;
  240. {
  241.     printf ("    { ");
  242.     str_print (cptr->ch_name);
  243.     printf (", ");
  244.     str_print (cptr->ch_show);
  245.     printf (", ");
  246.     table_print (cptr->ch_table);
  247.     printf (", ");
  248.     str_print (cptr->ch_queue);
  249.     printf (", ");
  250.     printf ("\n\t");
  251.     printf ("0%o, ", cptr->ch_access);
  252.     str_print (cptr->ch_ppath);
  253.     printf (", ");
  254.     str_print (cptr->ch_lname);
  255.     printf (", ");
  256.     str_print (cptr->ch_ldomain);
  257.     printf (", ");
  258.     str_print (cptr->ch_host);
  259.     printf (", ");
  260.     printf ("\n\t");
  261.     str_print (cptr->ch_login);
  262.     printf (", %d, ", (int)cptr->ch_poltime);
  263.     str_print (cptr->ch_trans);
  264.     printf (", ");
  265.     str_print (cptr->ch_script);
  266.     printf (", ");
  267.     printf ("\n\t");
  268.     table_print (cptr->ch_outsource);
  269.     printf (", ");
  270.     table_print (cptr->ch_insource);
  271.     printf (", ");
  272.     table_print (cptr->ch_outdest);
  273.     printf (", ");
  274.     table_print (cptr->ch_indest);
  275.     printf (", ");
  276.     table_print (cptr->ch_known);
  277.     printf (", ");
  278.     printf ("\n\t");
  279.     str_print (cptr->ch_confstr);
  280.     printf (", ");
  281.     printf ("0%o, ", cptr->ch_apout);
  282.     printf ("0%o, ", (int)cptr->ch_auth);
  283.     printf ("(Cache *)0,"); /* ch_dead */
  284.     printf ("\n\t");
  285.     printf ("0%o, ", cptr->ch_ttl);
  286.     str_print (cptr->ch_logfile);
  287.     printf (", ");
  288.     printf ("0%o", cptr->ch_loglevel);
  289.     printf (" },\n");
  290. }
  291.